package org.example.common;

import lombok.Data;

@Data
public class R<T> {

    private T data;
    private Integer code;
    private String msg;

    public static <T> R<T> ok(T object) {
        R<T> r = new R<>();
        r.data = object;
        r.code = 200;
        return r;
    }

    public static <T> R<T> ok() {
        R<T> r = new R<T>();
        r.code = 200;
        return r;
    }

    public static <T> R<T> fail(String msg) {
        R r = new R();
        r.msg = msg;
        r.code = 500;
        return r;
    }

    public static <T> R<T> fail(String msg, Integer code) {
        R r = new R();
        r.msg = msg;
        r.code = code;
        return r;
    }

}
